

import 'package:favorcate/core/model/meal_model.dart';
import 'package:favorcate/core/viewmodel/base_view_model.dart';
import 'package:flutter/material.dart';

class JKFavorViewModel extends BaseMealViewModel {

  // 添加meal
  void addMeal(JKHomeMealModel meal) {
    originMeals.add(meal);
    notifyListeners();
  }

  // 移除meal
  void removeMeal(JKHomeMealModel meal) {
    originMeals.remove(meal);
    notifyListeners();
  }

  // 判断某个没事是否被收藏
  bool isFavor(JKHomeMealModel meal) {
    return originMeals.contains(meal);
  }

  // 处理收藏
  void handleMeal(JKHomeMealModel meal) {
    if(isFavor(meal)) {
      removeMeal(meal);
    } else {
      addMeal(meal);
    }
  }
}
